package com.jcl.recruit.console.api.user;

import com.jcl.core.common.page.PageResult;
import com.jcl.core.resp.ApiResponse;
import com.jcl.recruit.console.user.model.vo.SysUserVo;
import com.jcl.recruit.console.user.service.ConsoleUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserController
 * @Author yyliu
 * @Date 2018/12/18 11:00
 * @Version 1.0
 **/
@RestController
@RequestMapping("/console/user")
public class UserBasicController {

    @Autowired
    private ConsoleUserService consoleUserService;

    @GetMapping("/pageList")
    public ApiResponse pageList(Integer curPage, Integer rowSize) {
        PageResult result = consoleUserService.pageList(curPage, rowSize);
        return ApiResponse.success(result);
    }

    @GetMapping("/get/{id}")
    public ApiResponse getOne(@PathVariable("id") Integer id) {
        SysUserVo result = consoleUserService.findOne(id);
        if (null == result) {
            return ApiResponse.error("请求对象不存在");
        }
        return ApiResponse.success(result);
    }

    @PostMapping("/add")
    public ApiResponse addUser(@RequestBody SysUserVo userVo) {
        int result = consoleUserService.updateUser(userVo);
        if (2 == result) {
            return ApiResponse.error("请求对象不存在");
        }
        return ApiResponse.success("操作成功");
    }

    @PostMapping("/update")
    public ApiResponse updateUser(@RequestBody SysUserVo userVo) {
        int result = consoleUserService.updateUser(userVo);
        if (2 == result) {
            return ApiResponse.error("请求对象不存在");
        }
        return ApiResponse.success("操作成功");
    }

    @GetMapping("/delete/{id}")
    public ApiResponse delete(@PathVariable("id") Integer id) {
        consoleUserService.deleteUser(id);
        return ApiResponse.success("操作成功");
    }

}
